﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;
using System.Collections;
using ExpertMIS.Entities;

namespace ExpertMIS.Admin
{
    public partial class BulletinList : ExpertMIS.Codes.AdminAuthenticationPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pgvBulletins.ObjectName = "ExpertMIS.BulletinListView";
            }

            pgvBulletins.DeleteClientScript = "if(!confirm('您确定要删除该公告吗？')) return false; ";
            pgvBulletins.EditClientURL = "~/Admin/BulletinForm.aspx?oid={0}";
            pgvBulletins.DeleteClientURL = "~/Admin/BulletinList.aspx?oid={0}&action=delete";

            string action = Request["action"];
            if (!string.IsNullOrEmpty(action))
            {
                string oid = Request["oid"];
                switch (action)
                {
                    case "delete":
                        DeleteBulletin(oid);
                        break;
                    default:
                        break;
                }
            }
        }

        protected void DeleteBulletin(string OID)
        {
            try
            {
                BulletinBroker broker = new BulletinBroker();
                Hashtable hsQuery = new Hashtable();
                hsQuery.Add("OID", OID);
                BulletinEntity entity = broker.GetEntity(hsQuery) as BulletinEntity;

                if (entity == null)
                {
                    return;
                }
                broker.RemoveEntity(entity, null);
            }
            catch
            {
                return;
            }
        }

        protected void lbNew_Click(object sender, EventArgs e)
        {
            Response.Redirect("BulletinForm.aspx");
        }
    }
}
